{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests #导⼊requests模块\n",
    "import json\n",
    "create_facelists_url = \"https://api-fangwx.cognitiveservices.azure.com/face/v1.0/facelists/{faceListId}\"\n",
    "subscription_key = \"415e308c1faf443da19e33cdbd30a6a3\"\n",
    "assert subscription_key\n",
    "headers = {\n",
    " # Request headers\n",
    " 'Content-Type': 'application/json',\n",
    " 'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、create 创建一个装相片的列表\n",
    "data = {\n",
    "    \"name\": \"facelist\",\n",
    "    \"userData\": \"names\",\n",
    "    \"recognitionModel\": \"recognition_02\"\n",
    "}\n",
    "params = {\n",
    "    # Request parameters    \n",
    "   \n",
    "    \"faceListId\":\"similar_faces\"\n",
    "    \n",
    "#     'detectionModel': 'detection_01',\n",
    "}\n",
    "r_create = requests.put(create_facelists_url,headers=headers,params=params,json=data)\n",
    "# 请求成功，返回空字符串\n",
    "r_create.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b''"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " r_create.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2、Add face\n",
    "add_face_url =\"https://api-fangwx.cognitiveservices.azure.com/face/v1.0/facelists/{faceListId}/persistedFaces\"\n",
    "subscription_key = \"415e308c1faf443da19e33cdbd30a6a3\"\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "img_url = \"http://b-ssl.duitang.com/uploads/item/201812/30/20181230222826_vxpys.jpg\"\n",
    "\n",
    "params_add_face={\n",
    "    \"faceListId\":\"similar_faces\",\n",
    "    \"userData\":\"jennie\"\n",
    "}\n",
    "\n",
    "r_add_face = requests.post(add_face_url,headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "# r = requests.post(add_face, headers=headers,params = params,json={\"url\": add_face_image})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 封装成函数方便添加图片\n",
    "def AddFace(img_url=str,userData=str):\n",
    "    add_face_url =\"https://api-fangwx.cognitiveservices.azure.com/face/v1.0/facelists/{faceListId}/persistedFaces\"\n",
    "    subscription_key = \"415e308c1faf443da19e33cdbd30a6a3\"\n",
    "    assert subscription_key\n",
    "    headers = {\n",
    "        # Request headers\n",
    "        'Content-Type': 'application/json',\n",
    "        'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "    }\n",
    "    img_url = img_url\n",
    "\n",
    "    params_add_face={\n",
    "        \"faceListId\":\"similar_faces\",\n",
    "        \"userData\":userData\n",
    "    }\n",
    "    r_add_face = requests.post(add_face_url,headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "    return r_add_face.status_code#返回出状态码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 顺便把查看列表的也给封装了\n",
    "# Get facelist\n",
    "def GetFacelist():\n",
    "    get_facelist_url = \"https://api-fangwx.cognitiveservices.azure.com/face/v1.0/facelists/{faceListId}\"\n",
    "    data = {\n",
    "        \"faceListId\":\"similar_faces\",\n",
    "    }\n",
    "    r_get_facelist = requests.get(get_facelist_url,headers=headers,params=data)\n",
    "    return r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"http://b-ssl.duitang.com/uploads/item/201810/01/20181001063027_yqvqv.thumb.700_0.jpg\",\"lisa\")\n",
    "AddFace(\"http://img3.imgtn.bdimg.com/it/u=2470226727,2547830866&fm=26&gp=0.jpg\",\"rose\")\n",
    "AddFace(\"http://b-ssl.duitang.com/uploads/item/201809/16/20180916203728_ZSANS.jpeg\",\"jisoo\")\n",
    "AddFace(\"http://spider.nosdn.127.net/61c2973e4cc199b2d8b05eeb49fc2882.jpeg\",\"hyuna\")\n",
    "AddFace(\"http://b-ssl.duitang.com/uploads/item/201712/24/20171224003446_LBRhA.jpeg\",\"hani\")\n",
    "AddFace(\"http://b-ssl.duitang.com/uploads/item/201806/19/20180619221621_urjdv.thumb.700_0.jpg\",\"seolhyun\")\n",
    "AddFace(\"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586808154927&di=12eb796cc4009298d9756c1cec5cf62d&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201810%2F21%2F20181021161407_miveo.jpg\",\"suzy\")\n",
    "AddFace(\"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586808270852&di=5a182f77ca0d00f99eb393e91da5be69&imgtype=0&src=http%3A%2F%2F00.minipic.eastday.com%2F20170629%2F20170629085430_7b5e31730b00eddb28ceb8e266eb7cae_2.jpeg\",\"naen\")\n",
    "AddFace(\"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586808332055&di=acac6b4245403dccd6f43bbd0a4a793a&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F779f6e41bfc4505d2cbc1d043c5f9eb744d131d274568-CL2PgE_fw658\",\"irene\")\n",
    "AddFace(\"http://5b0988e595225.cdn.sohucs.com/images/20190924/e6efa07fc4e74008a384052e5494052a.jpeg\",\"sonw\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'[{\"faceId\": \"ec58c975-2ddf-40b7-8cde-c1d70b8504dd\", \"faceRectangle\": {\"top\": 351, \"left\": 409, \"width\": 300, \"height\": 300}, \"faceAttributes\": {\"smile\": 0.0, \"headPose\": {\"pitch\": -9.6, \"roll\": 1.3, \"yaw\": -7.9}, \"gender\": \"female\", \"age\": 19.0, \"facialHair\": {\"moustache\": 0.0, \"beard\": 0.0, \"sideburns\": 0.0}, \"glasses\": \"ReadingGlasses\", \"emotion\": {\"anger\": 0.0, \"contempt\": 0.0, \"disgust\": 0.0, \"fear\": 0.0, \"happiness\": 0.0, \"neutral\": 0.996, \"sadness\": 0.002, \"surprise\": 0.003}, \"blur\": {\"blurLevel\": \"low\", \"value\": 0.0}, \"exposure\": {\"exposureLevel\": \"goodExposure\", \"value\": 0.46}, \"noise\": {\"noiseLevel\": \"high\", \"value\": 0.88}, \"makeup\": {\"eyeMakeup\": true, \"lipMakeup\": true}, \"accessories\": [], \"occlusion\": {\"foreheadOccluded\": false, \"eyeOccluded\": false, \"mouthOccluded\": false}, \"hair\": {\"bald\": 0.1, \"invisible\": false, \"hairColor\": [{\"color\": \"brown\", \"confidence\": 0.99}, {\"color\": \"black\", \"confidence\": 0.85}, {\"color\": \"gray\", \"confidence\": 0.24}, {\"color\": \"blond\", \"confidence\": 0.23}, {\"color\": \"red\", \"confidence\": 0.14}, {\"color\": \"other\", \"confidence\": 0.1}]}}}]'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3、检测人脸的id\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://api-fangwx.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "\n",
    "# 请求正文\n",
    "image_url = 'http://b-ssl.duitang.com/uploads/item/201812/30/20181230222826_vxpys.jpg'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "\n",
    "# 请求参数\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 选择model\n",
    "    'recognitionModel':'recognition_02',\n",
    "    'detectionModel':'detection_01',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "# json.dumps 将json--->字符串\n",
    "json.dumps(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "jennie = response.json()[0][\"faceId\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "#4、Find similars\n",
    "\n",
    "findsimilars_url = \"https://api-fangwx.cognitiveservices.azure.com/face/v1.0/findsimilars\"\n",
    "\n",
    "# 请求正文 faceId需要先检测一张照片获取\n",
    "data_findsimilars = {\n",
    "    \"faceId\":jennie,\n",
    "    \"faceListId\":\"similar_faces\",\n",
    "    \"maxNumOfCandidatesReturned\": 10,\n",
    "    \"mode\": \"matchFace\"#matchPerson\n",
    "    }\n",
    "\n",
    "r_findsimilars = requests.post(findsimilars_url,headers=headers,json=data_findsimilars)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'persistedFaceId': '46c61d10-e6e2-4c61-bfe3-9673836fcbbe',\n",
       "  'confidence': 1.0},\n",
       " {'persistedFaceId': '63ae8c78-b8c7-4925-bc4a-c6a2ad59189d',\n",
       "  'confidence': 0.71018},\n",
       " {'persistedFaceId': '2210c307-8f8b-4174-8ec8-74d1180757aa',\n",
       "  'confidence': 0.29656},\n",
       " {'persistedFaceId': '9bb6247a-0ea5-4a48-8348-86be363cf448',\n",
       "  'confidence': 0.17495},\n",
       " {'persistedFaceId': 'ebcc85e7-635d-406c-858b-e15e45abb137',\n",
       "  'confidence': 0.12588},\n",
       " {'persistedFaceId': '175d521e-3002-421c-b00d-53a352e80b80',\n",
       "  'confidence': 0.1186},\n",
       " {'persistedFaceId': '607bfd2c-4790-4b18-b89d-ae993c08b705',\n",
       "  'confidence': 0.11799},\n",
       " {'persistedFaceId': '9d22a708-d7c2-4a2c-a762-a84b2d96b175',\n",
       "  'confidence': 0.11228},\n",
       " {'persistedFaceId': '7e793395-8872-4e24-a9b8-817748057366',\n",
       "  'confidence': 0.09181},\n",
       " {'persistedFaceId': 'f4b386d6-4466-4746-8173-a90ad44ae6b4',\n",
       "  'confidence': 0.0868}]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [{'persistedFaceId': '46c61d10-e6e2-4c61-bfe3-9673836fcbbe',\n",
       "   'userData': 'jennie'},\n",
       "  {'persistedFaceId': '7e793395-8872-4e24-a9b8-817748057366',\n",
       "   'userData': 'lisa'},\n",
       "  {'persistedFaceId': 'f4b386d6-4466-4746-8173-a90ad44ae6b4',\n",
       "   'userData': 'jisoo'},\n",
       "  {'persistedFaceId': '9bb6247a-0ea5-4a48-8348-86be363cf448',\n",
       "   'userData': 'hyuna'},\n",
       "  {'persistedFaceId': 'ebcc85e7-635d-406c-858b-e15e45abb137',\n",
       "   'userData': 'hani'},\n",
       "  {'persistedFaceId': '2210c307-8f8b-4174-8ec8-74d1180757aa',\n",
       "   'userData': 'seolhyun'},\n",
       "  {'persistedFaceId': '175d521e-3002-421c-b00d-53a352e80b80',\n",
       "   'userData': 'suzy'},\n",
       "  {'persistedFaceId': '63ae8c78-b8c7-4925-bc4a-c6a2ad59189d',\n",
       "   'userData': 'naen'},\n",
       "  {'persistedFaceId': '9d22a708-d7c2-4a2c-a762-a84b2d96b175',\n",
       "   'userData': 'irene'},\n",
       "  {'persistedFaceId': '607bfd2c-4790-4b18-b89d-ae993c08b705',\n",
       "   'userData': 'sonw'}],\n",
       " 'faceListId': 'similar_faces',\n",
       " 'name': 'facelist',\n",
       " 'userData': 'names'}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd \n",
    "get_facelist_url = \"https://api-fangwx.cognitiveservices.azure.com/face/v1.0/facelists/{faceListId}\"\n",
    "\n",
    "data = {\n",
    "    \"faceListId\":\"similar_faces\",\n",
    "\n",
    "}\n",
    "\n",
    "r_get_facelist = requests.get(get_facelist_url,headers=headers,params=data)\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>46c61d10-e6e2-4c61-bfe3-9673836fcbbe</td>\n",
       "      <td>jennie</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7e793395-8872-4e24-a9b8-817748057366</td>\n",
       "      <td>lisa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>f4b386d6-4466-4746-8173-a90ad44ae6b4</td>\n",
       "      <td>jisoo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9bb6247a-0ea5-4a48-8348-86be363cf448</td>\n",
       "      <td>hyuna</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ebcc85e7-635d-406c-858b-e15e45abb137</td>\n",
       "      <td>hani</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2210c307-8f8b-4174-8ec8-74d1180757aa</td>\n",
       "      <td>seolhyun</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>175d521e-3002-421c-b00d-53a352e80b80</td>\n",
       "      <td>suzy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>63ae8c78-b8c7-4925-bc4a-c6a2ad59189d</td>\n",
       "      <td>naen</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9d22a708-d7c2-4a2c-a762-a84b2d96b175</td>\n",
       "      <td>irene</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>607bfd2c-4790-4b18-b89d-ae993c08b705</td>\n",
       "      <td>sonw</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId  userData\n",
       "0  46c61d10-e6e2-4c61-bfe3-9673836fcbbe    jennie\n",
       "1  7e793395-8872-4e24-a9b8-817748057366      lisa\n",
       "2  f4b386d6-4466-4746-8173-a90ad44ae6b4     jisoo\n",
       "3  9bb6247a-0ea5-4a48-8348-86be363cf448     hyuna\n",
       "4  ebcc85e7-635d-406c-858b-e15e45abb137      hani\n",
       "5  2210c307-8f8b-4174-8ec8-74d1180757aa  seolhyun\n",
       "6  175d521e-3002-421c-b00d-53a352e80b80      suzy\n",
       "7  63ae8c78-b8c7-4925-bc4a-c6a2ad59189d      naen\n",
       "8  9d22a708-d7c2-4a2c-a762-a84b2d96b175     irene\n",
       "9  607bfd2c-4790-4b18-b89d-ae993c08b705      sonw"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "adf = pd.json_normalize(r_get_facelist.json()[\"persistedFaces\"])# 升级pandas才能运行\n",
    "adf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>46c61d10-e6e2-4c61-bfe3-9673836fcbbe</td>\n",
       "      <td>1.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>63ae8c78-b8c7-4925-bc4a-c6a2ad59189d</td>\n",
       "      <td>0.71018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2210c307-8f8b-4174-8ec8-74d1180757aa</td>\n",
       "      <td>0.29656</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9bb6247a-0ea5-4a48-8348-86be363cf448</td>\n",
       "      <td>0.17495</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ebcc85e7-635d-406c-858b-e15e45abb137</td>\n",
       "      <td>0.12588</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>175d521e-3002-421c-b00d-53a352e80b80</td>\n",
       "      <td>0.11860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>607bfd2c-4790-4b18-b89d-ae993c08b705</td>\n",
       "      <td>0.11799</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>9d22a708-d7c2-4a2c-a762-a84b2d96b175</td>\n",
       "      <td>0.11228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>7e793395-8872-4e24-a9b8-817748057366</td>\n",
       "      <td>0.09181</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>f4b386d6-4466-4746-8173-a90ad44ae6b4</td>\n",
       "      <td>0.08680</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId  confidence\n",
       "0  46c61d10-e6e2-4c61-bfe3-9673836fcbbe     1.00000\n",
       "1  63ae8c78-b8c7-4925-bc4a-c6a2ad59189d     0.71018\n",
       "2  2210c307-8f8b-4174-8ec8-74d1180757aa     0.29656\n",
       "3  9bb6247a-0ea5-4a48-8348-86be363cf448     0.17495\n",
       "4  ebcc85e7-635d-406c-858b-e15e45abb137     0.12588\n",
       "5  175d521e-3002-421c-b00d-53a352e80b80     0.11860\n",
       "6  607bfd2c-4790-4b18-b89d-ae993c08b705     0.11799\n",
       "7  9d22a708-d7c2-4a2c-a762-a84b2d96b175     0.11228\n",
       "8  7e793395-8872-4e24-a9b8-817748057366     0.09181\n",
       "9  f4b386d6-4466-4746-8173-a90ad44ae6b4     0.08680"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bdf = pd.json_normalize(r_findsimilars.json())# 升级pandas才能运行\n",
    "bdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>46c61d10-e6e2-4c61-bfe3-9673836fcbbe</td>\n",
       "      <td>jennie</td>\n",
       "      <td>1.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>63ae8c78-b8c7-4925-bc4a-c6a2ad59189d</td>\n",
       "      <td>naen</td>\n",
       "      <td>0.71018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2210c307-8f8b-4174-8ec8-74d1180757aa</td>\n",
       "      <td>seolhyun</td>\n",
       "      <td>0.29656</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9bb6247a-0ea5-4a48-8348-86be363cf448</td>\n",
       "      <td>hyuna</td>\n",
       "      <td>0.17495</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ebcc85e7-635d-406c-858b-e15e45abb137</td>\n",
       "      <td>hani</td>\n",
       "      <td>0.12588</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>175d521e-3002-421c-b00d-53a352e80b80</td>\n",
       "      <td>suzy</td>\n",
       "      <td>0.11860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>607bfd2c-4790-4b18-b89d-ae993c08b705</td>\n",
       "      <td>sonw</td>\n",
       "      <td>0.11799</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9d22a708-d7c2-4a2c-a762-a84b2d96b175</td>\n",
       "      <td>irene</td>\n",
       "      <td>0.11228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7e793395-8872-4e24-a9b8-817748057366</td>\n",
       "      <td>lisa</td>\n",
       "      <td>0.09181</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>f4b386d6-4466-4746-8173-a90ad44ae6b4</td>\n",
       "      <td>jisoo</td>\n",
       "      <td>0.08680</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId  userData  confidence\n",
       "0  46c61d10-e6e2-4c61-bfe3-9673836fcbbe    jennie     1.00000\n",
       "7  63ae8c78-b8c7-4925-bc4a-c6a2ad59189d      naen     0.71018\n",
       "5  2210c307-8f8b-4174-8ec8-74d1180757aa  seolhyun     0.29656\n",
       "3  9bb6247a-0ea5-4a48-8348-86be363cf448     hyuna     0.17495\n",
       "4  ebcc85e7-635d-406c-858b-e15e45abb137      hani     0.12588\n",
       "6  175d521e-3002-421c-b00d-53a352e80b80      suzy     0.11860\n",
       "9  607bfd2c-4790-4b18-b89d-ae993c08b705      sonw     0.11799\n",
       "8  9d22a708-d7c2-4a2c-a762-a84b2d96b175     irene     0.11228\n",
       "1  7e793395-8872-4e24-a9b8-817748057366      lisa     0.09181\n",
       "2  f4b386d6-4466-4746-8173-a90ad44ae6b4     jisoo     0.08680"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(adf, bdf,how='inner', on='persistedFaceId').sort_values(by=\"confidence\",ascending = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
